<template>
  <div>
    <van-nav-bar title="设置密码" left-text="返回" left-arrow @click-left="onClickLeft" />

    <van-cell-group inset>
      <van-field v-model="checktel" name="username" label="手机号" placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]" />
      <van-field v-model="password" :type="flag ? 'password' : 'text'" name="password" label="密码" placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]" :right-icon="flag ? 'eye-o' : 'closed-eye'"
        @click-right-icon="flag=!flag" />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit" @click="sendPass">
        提交
      </van-button>
    </div>

  </div>
</template>

<script>
import { goRegister } from '@/apis/wode';
export default {
  data() {
    return {
      checktel: '',
      password: '',
      flag: false
    }
  },
  methods: {
    onClickLeft() {
      history.back()
    },
    sendPass() {
      goRegister({ loginname: this.checktel, password: this.password }).then(res => {
        console.log(res);
        if (res.data.code == 1001) {
          return showToast("用户名已存在")
        } else if (res.data.code == 200) {
          this.$router.push("/login")
        } else {
          return showToast("注册失败，我也不知道为啥")
        }
      })
    }
  },
  created() {
    this.checktel = localStorage.getItem("tel")
  }
}
</script>

<style lang="less" scoped></style>